<template>
  <div class="app-container">
    <el-form>
      <el-form-item label="自我评价">
        <el-input
          v-model="personalInfo.detail"
          type="textarea"
          placeholder="请输入内容"
          maxlength="200"
          show-word-limit
          size="medium"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="saveOrUpdate">保存</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
import personal_info from '@/api/hr/personal_info'

export default {
  data() {
    return {
      personalInfo: {}
    }
  },
  created() {
    this.get_personalInfo()
  },
  methods: {
    get_personalInfo() {
      personal_info.get_personalInfo().then(response => {
        if (response.data.personalInfo !== undefined && response.data.personalInfo != null) {
          this.personalInfo = response.data.personalInfo
        }
      })
    },
    saveOrUpdate() {
      // eslint-disable-next-line eqeqeq
      if (this.personalInfo.id === undefined || this.personalInfo.id == null) {
        this.save()
      } else {
        this.update()
      }
    },
    save() {
      personal_info.add_personalInfo(this.personalInfo).then(response => {
        this.$message({
          type: 'success',
          message: '修改成功'
        })
        this.$router.push({ path: '/resume/base-info' })
      }).catch(response => {
        this.$message({
          type: 'error',
          message: '修改失败'
        })
      })
    },
    update() {
      personal_info.update_personalInfo(this.personalInfo).then(response => {
        this.$message({
          type: 'success',
          message: '修改成功'
        })
        this.$router.push({ path: '/resume/base-info' })
      }).catch(response => {
        this.$message({
          type: 'error',
          message: '修改失败'
        })
      })
    }
  }
}
</script>
